package com.arvato.minipro.controller.front.mall;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.arvato.minipro.bean.bean_dto.common.PageData;
import com.arvato.minipro.bean.bean_dto.common.Query;
import com.arvato.minipro.bean.bean_dto.common.Result;
import com.arvato.minipro.bean.bean_vo.mall.EcCommodityVo;
import com.arvato.minipro.service.mall.CommodityService;

/**
 * 
 * @author: smallking
 * 
 * @Descibe:前台商品相关的Controller
 * 
 * @Date: 2018年5月4日  下午4:26:10
 */
@Controller
@RequestMapping(value = "/mall/commodity")
public class CommodityController {
	
	@Autowired
	private CommodityService commodityService;
	
	/**
	 * 查询商品列表
	 * @param param
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/list", method = {RequestMethod.POST})
	public PageData list(@RequestParam Map<String, Object> param){
		Query query = new Query(param);
		query.put("status", 1);
		if(query.get("commodityIds") != null) {
		    List<String> list = new ArrayList<String>();
			for(String commodityId : (query.get("commodityIds") + "").split(",")) {
				list.add(commodityId);
			}
			query.put("commodityIds", list);
		}
		PageData pageData = commodityService.listCommodityByQuery(query, query.getPageNum(), query.getPageSize());
		pageData.setFront(true);
		return pageData;
	}
	
	/**
	 * 查询商品详情
	 * @param param
	 * @return 
	 */
	@ResponseBody
	@RequestMapping(value = "/detail", method = {RequestMethod.POST})
	public Result detail(String commodityId){
		Result result = new Result(true);
		EcCommodityVo commodityVo = commodityService.getCommodityById(commodityId);
		result.setData(commodityVo);
		return result;
	}	
}
